package com.yuntongxun.ecdemo.voicechat.ui.adapter;

import android.content.Context;
import android.graphics.BitmapFactory;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.text.SpannableString;
import android.text.Spanned;
import android.text.style.ForegroundColorSpan;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.yuntongxun.ecdemo.R;
import com.yuntongxun.ecdemo.voicechat.bean.Group;
import com.yuntongxun.ecdemo.voicechat.bean.UserInfo;
import com.yuntongxun.ecdemo.voicechat.listeners.IRecyclerViewItemListener;
import com.yuntongxun.ecdemo.voicechat.view.MyImageSpan;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;

/**
 * Created by zhuonan on 2016/11/25.
 */

public class GroupAdapter extends RecyclerView.Adapter {


    private Context mContext;
    private List<Group> notes;
    private IRecyclerViewItemListener mListener;

    public GroupAdapter(Context context, List<Group> noteList, IRecyclerViewItemListener myItemClickListener) {
        mContext = context;
        notes = noteList;
        mListener = myItemClickListener;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View v = View.inflate(parent.getContext(), R.layout.adapter_group_item, null);
        return new ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ViewHolder viewHolder=(ViewHolder)holder;
        viewHolder.textView.setText(notes.get(position).getName());
    }

    @Override
    public int getItemCount() {
        if (notes!=null){
            return notes.size();
        }
        return 0;
    }

    public class ViewHolder extends RecyclerView.ViewHolder{


        @InjectView(R.id.group_info)
        TextView textView;


        public ViewHolder(View view) {
            super(view);
            ButterKnife.inject(this, view);
        }

        @OnClick(R.id.card_view_layout)
        public void clickItem() {
            if (mListener != null) {
                mListener.onItemClick(getPosition());
            }
        }
    }
}
